package com.scau.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.scau.pojo.Messagecomment;
import com.scau.service.CommentService;

@RestController
@RequestMapping("/commentController")
public class CommentController{

	@Autowired
	CommentService commentService;
	
	@RequestMapping("/queryCommentBymsId")
	public List<Messagecomment> query(@RequestParam int msId) {
		return commentService.query(msId);
	}
	
	@RequestMapping("/editComment")
	public int edit(@RequestBody JSONObject jsonObject) throws Exception{
		int result=0;
		try{
			result=commentService.update(jsonObject);
		}catch(Exception e){
			e.getMessage();
		}
		return result;
	}
	
	@RequestMapping("/delComment")
	public int edit(@RequestParam int id) throws Exception{
		int result=0;
		try{
			result=commentService.deleteComment(id);
		}catch(Exception e){
			e.getMessage();
		}
		return result;
	}
	
	@RequestMapping("/deleteComments")
	public int deleteMulti(@RequestBody JSONArray jsonArray) throws Exception{
		int result=0;
		try{
			result=commentService.deleteComments(jsonArray);
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		return result;
	}
	
	@RequestMapping("/addComment")
	public int addComment(@RequestBody JSONObject jsonObject) throws Exception{
		int result=0;
		try{
			result=commentService.addComment(jsonObject);
		}catch(Exception e){
			e.getMessage();
		}
		return result;
	}

}
